x= input()
 
if len(str(x)) != 4:
    print(0)
else:
    k = False
    for length in range(4, 0, -1):
        if k:
            break
        for i in range(4 - length + 1):
            s = int(str(x)[i:i+length])
            if s < 2:
                continue
            for j in range(2, int(s**0.5) + 1):
                if s % j == 0:
                    break
            else:
                print(s)
                k = True
                break
    if not k:
        print(0)
